//*********************************************************
//
// Output Registers used:
//   oPos - The vertex output position.
//   oT0  - original UV
//   oD0  - diffuse color
//   oD1  - specular color
//
//*********************************************************

// oPos = MVP * position
m4x4 r0, inPos, c[MODEL_VIEW_PROJECTION]
mov oPos, r0

// oT0 = texcoord
mov oT0, inUV

;// write oT1  to fight the bug...
mov oT1, inUV

// r0 = View vector
sub r0, c[MODEL_SPACE_CAMERA_POS_OOFOG_RANGE], inPos	// r0 = CameraPos - inPos
dp3 r1.x, r0, r0
rsq r1.x, r1.x
mul r0, r0, r1.x	// r0 = ViewVec

// r0 = Reflection vector
dp3 r3.xyz, r0, inNormal		// r3.xyz = (V.N)
add r2.xyz, inNormal, inNormal		// r2 = 2 * N
mad r0.xyz, r3, r2, -r0			// r0 = 2N(V.N)-V

// Directional light color
dp3 r5.x, inNormal, c[VL_MODEL_SPACE_LIGHT_DIR_SHADOWLENGTH]
dp3 r5.y, r0, c[VL_MODEL_SPACE_LIGHT_DIR_SHADOWLENGTH]
mov r5.w, c[MATERIAL_SPECULAR_POWER].w

lit r4, r5	// We have diffuse in y, specular in z

mul r0, r4.y, c[VL_DLIGHT_DIFFUSE_1]
mul oD0.rgb, r0, c[MATERIAL_DIFFUSE_OPACITY]
mul oD0.a, inNormal.w, c[MATERIAL_DIFFUSE_OPACITY]

mul r0, r4.z, c[VL_DLIGHT_SPECULAR_1]
mul oD1.rgb, r0, c[MATERIAL_SPECULAR_POWER]
mov oD1.a, c[CONSTANT_0_05_1_2].x
